class Originator {
    private _state: string = ""

    public get state(): string {
        return this._state
    }
    public set state(value: string) {
        this._state = value
    }


    public createMemento(): Memento {
        console.log("创建一个备忘录")
        return new Memento(this._state)
    }

    public saveMemento(memento: Memento) {
        console.log("恢复一个备忘录")
        this._state = memento.state
    }
}

class Memento {
    private _state: string

    constructor(state: string) {
        this._state = state
    }

    public get state(): string {
        return this._state
    }
}

class MementoManager {
    //保存单次状态
    private _memento?: Memento | undefined
    //保存多次状态
    private _mementoList?: Array<Memento> | undefined

    public get mementoList(): Array<Memento> | undefined {
        return this._mementoList
    }
    public set mementoList(value: Array<Memento> | undefined) {
        this._mementoList = value
    }


    public get memento(): Memento | undefined {
        return this._memento
    }
    public set memento(value: Memento | undefined) {
        this._memento = value
    }

}

const MementoTest = (): void => {
    const originator: Originator = new Originator()
    const mementoManager: MementoManager = new MementoManager()
    const memento :Memento = originator.createMemento()
    mementoManager.memento = memento
    originator.saveMemento(memento)
}

MementoTest()